﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using Presentation.ServiceAgent.MembershipServiceAgent;

namespace Presentation.ServiceAgent.MembershipService
{

    /// <summary>
    /// Implementation of  Membership service client contract
    /// </summary>
    public class MemberShipServiceClient : IMemberShipServiceClient
    {
        #region members

        MembershipServiceAgent.MembershipServiceClient serviceClient;
        #endregion


        #region ctor
        public MemberShipServiceClient()
        {
            serviceClient = new MembershipServiceAgent. MembershipServiceClient();
        }
        #endregion


        #region IMemberShipServiceClient memebers





        /// <summary>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </summary>
        /// <param name="username">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        ///<param name="password">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <param name="email">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <param name="passwordQuestion">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <param name="isApproved">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <param name="providerUserKey">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <returns>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </returns>
        /// <exception cref="System.Exception">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </exception>
        public Membership CreateUser(Membership newMember)
        {
            try
            {
                return serviceClient.CreateUser(newMember);
            }
            catch (FaultException<ApplicationServiceError> ex)
            {
                throw new Exception(ex.Detail.ErrorMessage);
            }
        }

        /// <summary>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </summary>
        /// <param name="username">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        ///<param name="password">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <returns>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </returns>
        public bool ValidateUser(string username, string password)
        {
            try{
                 return serviceClient.ValidateUser(username, password);
            }
            catch (FaultException<ApplicationServiceError> ex)
            {
                throw new Exception(ex.Detail.ErrorMessage);
            }
        }


        /// <summary>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </summary>
        /// <param name="username">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        ///<param name="password">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <returns>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </returns>
        public Membership GetUser(string username, bool userIsOnline)
        {
            return serviceClient.GetUser(username, userIsOnline);
        }

        /// <summary>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </summary>
        /// <param name="username">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        ///<param name="password">
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </param>
        /// <returns>
        /// <see cref="Presentation.ServiceAgent.MembershipService.IMemberShipServiceClient"/>
        /// </returns>
        public bool DeleteUser(string username, bool deleteAllRelatedData)
        {
            return serviceClient.DeleteUser(username, deleteAllRelatedData);
        }

        #endregion 
    }
}
